﻿using System;
using System.Diagnostics;
using CommandLineParser.Arguments;

namespace uTILLIty.Rave.Commandline
{
  /// <summary>
  /// A base class for all commandline commands
  /// </summary>
	abstract public class BaseCommand : ICommand
	{
    /// <summary>
    /// Invokes <see cref="OnExecute"/> on the implementation
    /// </summary>
		public void Execute()
		{
			OnExecute();
		}

    /// <summary>
    /// Invoked when the command is executed from the commandline
    /// </summary>
		protected abstract void OnExecute();

    /// <summary>
    /// Logs/writes an exception to the user
    /// </summary>
		protected virtual void WriteException(Exception ex)
		{
			switch (LogLevel)
			{
				case SourceLevels.Verbose:
				case SourceLevels.All:
					Console.WriteLine(ex);
					break;
				default:
					Program.WriteException(ex);
					break;
			}
		}

		/// <summary>
		/// Default: Information. Possible: All, Verbose, Information, Warning, Error, Critical
		/// </summary>
		[ValueArgument(typeof(SourceLevels), 'v', "verbosity", DefaultValue = SourceLevels.Information, Optional = true,
			Description = "Default: Information. Possible: All, Verbose, Information, Warning, Error, Critical", Example = "-v All")]
		public SourceLevels LogLevel;

	}
}